<template>
    <div class="components_edit_modal">
        <el-dialog title="确认课程表信息" :visible.sync="state" :show-close="true" :close-on-click-modal="false">
            <div class="scrollBarX">
                <el-table :data="syllabusList" border style="width: 100%" height="350">
                    <el-table-column :show-overflow-tooltip="true" prop="professionName" align="center" label="专业"></el-table-column>
                    <el-table-column :show-overflow-tooltip="true" prop="shortName" align="center" label="班级"></el-table-column>
                    <el-table-column :show-overflow-tooltip="true" prop="courseName" align="center" label="课程名称"></el-table-column>
                    <el-table-column :show-overflow-tooltip="true" prop="username" align="center" label="教师"></el-table-column>
                    <el-table-column :show-overflow-tooltip="true" prop="teachWeek" align="center" label="教学周">
                        <template slot-scope="scope">
                            第{{scope.row.teachWeek}}周
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" prop="week" align="center" label="星期">
                        <template slot-scope="scope">
                            {{weekArr[scope.row.week-1]}}
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" prop="section" align="center" label="节次">
                        <template slot-scope="scope">
                            第{{scope.row.section}}节
                        </template>
                    </el-table-column>
                    <el-table-column :show-overflow-tooltip="true" prop="teachPlace" align="center" label="上课地点"></el-table-column>
                </el-table>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary"
                @click="creatSyllabus"
                v-loading.fullscreen.lock="fullscreenLoading"
                size="small">确 定</el-button>
                <el-button @click="state = false" size="small">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {enums} from '@/constant'
    import {config} from '@/config'
    export default {
        components: {
        },
        data() {
            return {
                self: this,
                state: false,
                weekArr:["星期一","星期二","星期三","星期四","星期五","星期六","星期日"],
                fullscreenLoading: false,    //  loading
                syllabusList:[],
                baseId:null,
                options: {
                    week:[{
                          value: '1',
                          label: '周一'
                        }, {
                          value: '2',
                          label: '周二'
                        }, {
                          value: '3',
                          label: '周三'
                        }, {
                          value: '4',
                          label: '周四'
                        }, {
                          value: '5',
                          label: '周五'
                        }, {
                          value: '6',
                          label: '周六'
                        }, {
                          value: '7',
                          label: '周日'
                        }],
                    section:[{
                            value: '1',
                            label: '第一节'
                        },{
                            value: '2',
                            label: '第二节'
                        },{
                            value: '3',
                            label: '第三节'
                        },{
                            value: '4',
                            label: '第四节'
                        },{
                            value: '5',
                            label: '第五节'
                        },{
                            value: '6',
                            label: '第六节'
                        },{
                            value: '7',
                            label: '第七节'
                        },{
                            value: '8',
                            label: '第八节'
                        },{
                            value: '9',
                            label: '第九节'
                        },{
                            value: '10',
                            label: '第十节'
                        }]
                }
            };
        },
        created() {
            // this.getSyllabusList();
        },
        mounted() {},
        watch: {},
        methods: {
            // 打开模态框
            showDialog(val,baseId){
                this.professionId = val;
                this.baseId = baseId;
                this.getSyllabusList();
                // this.state = true;
                // this.getWeekList();homeworkTable
            },
            //请求课程表信息 初始数据
            getSyllabusList(){
                let self = this;
                self.axios.get(api.syllabusManager.getDetailConfirm + self.baseId).then((response) => {
                    if(response.data.success){
                        if(response.data.data.length > 0){
                            self.syllabusList = JSON.parse(JSON.stringify(response.data.data));
                            self.state = true;
                        }else{
                            // 操作失败
                            self.$message({
                                message: "还没有配置课程表信息！",
                                type:'error',
                                center: true
                            });
                        }
                    }else{
                        // 操作失败
                        self.$message({
                            message: response.data.msg,
                            type:'error',
                            center: true
                        });
                    }

                });
            },
            //保存课程表
            ensureSyllabus(){
                let self = this;
                self.fullscreenLoading = true;
                _.forEach(self.syllabusList, function(item){
                    // item.classId = item.classNo;
                    item.section = item.section.split(',');
                });
                self.axios.post(api.syllabusManager.syllabusInsert,self.syllabusList).then((response) => {
                    if(response.data.success){
                        self.state = true;
                    }else{
                        // 操作失败
                        self.$message({
                            message: response.data.msg,
                            type:'error',
                            center: true
                        });
                    }
                    self.fullscreenLoading = false;
                });
            },
            creatSyllabus(){
                let self = this;
                self.fullscreenLoading = true;
                self.axios.get(api.syllabusManager.generateSyllabus + self.baseId).then((response) => {
                    if(response.data.success){
                        self.state = false;
                        self.$emit('refreshList');
                    }else{
                        // 操作失败
                        self.$message({
                            message: response.data.msg,
                            type:'error',
                            center: true
                        });
                    }
                    self.fullscreenLoading = false;
                });
            }

        },
    };
</script>
<style scoped>
.el-input__inner{
    height: 20px;
}
.address{
    height:25px;
}
.el-textarea__inner{
    width:100%;
    height: 100%;
}
.components_edit_modal .el-table__body-wrapper td{
    padding: 5px;
}
.el-checkbox{
    /* display: block; */
}
.el-checkbox+.el-checkbox{ /* margin-left: 0px; */ }
.el-row {
    margin-bottom: 20px;
  }
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #99a9bf;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
  .box-card{
    position: relative;
  }
  .card-delect{
    position: absolute;
    top: -10px;
    right: -10px;
    background: #00bbbd;
    width: 30px;
    height: 30px;
    line-height:30px;
    color: #FFF;
    text-align: center;
    border-radius: 50%;
  }
  .el-card{
    overflow: inherit;
  }
</style>